package com.example.tvidemo.service;

import com.example.tvidemo.entity.Permission;
import com.example.tvidemo.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    public List<Permission> findAll(){
        return permissionMapper.findAll();
    }

    public Permission findById(String id){
        return permissionMapper.findById(id);
    }

    public void addPermission(Permission permission){
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        permission.setId(uuid);
        permissionMapper.addPermission(permission);
    }

    public void updatePermission(Permission permission){
        permissionMapper.updatePermission(permission);
    }

    public void deletePermission(String id){
        permissionMapper.deletePermission(id);
    }

    public void authorizePermission(String roleId,String permissionId){
        permissionMapper.authorizePermission(roleId,permissionId);
    }
}
